#ifndef DVMAPVIEW_H
#define DVMAPVIEW_H

#include <QGraphicsView>

class dvMapScene;

class dvMapView : public QGraphicsView
{
    Q_OBJECT

public:
    enum RendererType { Native, OpenGL, Image };

    dvMapView(dvMapScene *scene, QWidget *parent = 0);
    ~dvMapView();

    void drawBackground(QPainter *p, const QRectF &rect);
    void loadBackgroundImage(const QString& file);
    void createBackgroundImage(int width, int height, const QColor& color);
    void setRenderer(RendererType type = Native);
    void openMap(const QString& fname);

    void hideBackgroundImage(bool hide);
    void setBackgroundColor(QColor color);
    void setBackgroundDefault();
    
signals:
    
public slots:
    void setHighQualityAntialiasing(bool highQualityAntialiasing);
    void setViewBackground(bool enable);
    void setViewOutline(bool enable);

protected:
    void wheelEvent(QWheelEvent *event);
    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void resizeEvent(QResizeEvent *event);

private:
    RendererType       m_renderer;
    QImage             m_image;
    QColor             m_color;

    dvMapScene        *m_pScene;

    QGraphicsItem     *m_documentItem;
    QGraphicsRectItem *m_backgroundItem;
    QGraphicsRectItem *m_outlineItem;

    bool    m_LeftMouseButtonPressed;
    bool    m_HandMode;

    QPoint  m_LastLButtonPressedPoint;

    double  m_globalScaleFactor;

protected:
    //Holds the current centerpoint for the view, used for panning and zooming
    QPointF CurrentCenterPoint;
    //From panning the view
    QPoint LastPanPoint;
    //Set the current centerpoint in the
    void SetCenter(const QPointF& centerPoint);
    QPointF GetCenter() { return CurrentCenterPoint; }

public:
    void setHandMode(bool hand);
};

#endif // DVMAPVIEW_H
